<template>
	<uni-section title="详细信息" type="line">
	<view>
		<view>
			<uni-forms ref="form"  :model="form" required>
				<uni-row>
					<uni-col :span="11" class="title1">设备编号:</uni-col>
					<uni-col :span="11" class="content1">{{form.instrumentId}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="11" class="title">规格:</uni-col>
					<uni-col :span="11" class="content">{{form.specification}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="5" class="title">领用单位:</uni-col>
					<uni-col :span="18" class="content">{{form.applicationDepartment}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="11" class="title" >设备类型:</uni-col>
					<uni-col :span="11" class="content">{{type(form.equipmentType)}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="5" class="title">设备名称:</uni-col>
					<uni-col :span="18" class="content">{{form.instrumentName}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="11" class="title">领用人姓名:</uni-col>
					<uni-col :span="11" class="content">{{form.receiverName}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="11" class="title">领用人工号:</uni-col>
					<uni-col :span="11" class="content">{{form.receiverId}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="5" class="title">存放地点:</uni-col>
					<uni-col :span="18" class="content">{{form.storageLocation}}</uni-col>
				</uni-row>
				<view class="divider" />
				<uni-row>
		<!-- 			<uni-forms-item :span="10" class="title" required>开始时间:</uni-forms-item>
					<uni-datetime-picker class="uni1" :border="false" type="datetime" v-model="form.appointmentStart"
						:start="range.StartTime" :end="range.EndTime" :clear-icon="false" /> -->
					<uni-col :span="6" class="title" >开始时间:</uni-col>
					<uni-datetime-picker class="uni1" :border="false" type="datetime" v-model="form.appointmentStart"
						:start="range.StartTime" :end="range.EndTime" :clear-icon="false" />
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="6" class="title">结束时间:</uni-col>
					<uni-datetime-picker class="uni1" :border="false" type="datetime" v-model="form.appointmentEnd"
						:start="range.StartTime" :end="range.EndTime" :clear-icon="false" />
				</uni-row>
				<view class="divider" />
				<!-- <uni-row>
					<uni-col :span="9" class="title">经费科目:</uni-col>
					<uni-easyinput class="uni" :inputBorder="false" v-model="form.expenditureSubject"
						placeholder="请输入内容" @input="input"></uni-easyinput>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="9" class="title">使用方向:</uni-col>
					<uni-easyinput  class="uni" :inputBorder="false" v-model="form.useDirection" placeholder="请输入内容"
						@input="input"></uni-easyinput>
				</uni-row>
				<view class="divider" /> -->
				<uni-row>
					<uni-col :span="19" class="title">经费科目:</uni-col>
				
					<uni-data-select class="uni2" v-model="form.expenditureSubject" :localdata="name1" @change="change" :clear="false" >
					</uni-data-select>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="19" class="title">使用方向:</uni-col>
				
					<uni-data-select class="uni2" v-model="form.useDirection" :localdata="name1" @change="change" :clear="false" >
					</uni-data-select>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="19" class="title">首次使用:</uni-col>

					<uni-data-select class="uni2" v-model="form.firstUse" :localdata="name2" @change="change" :clear="false" >
					</uni-data-select>
				</uni-row>
				<view class="divider" />
				<uni-row>
					<uni-col :span="9" class="title">提交日期:</uni-col>
					<uni-datetime-picker class="uni1" :border="false" type="date" :clear-icon="false"
						v-model="form.sbumitTime" @maskClick="maskClick" :disabled="true" />
				</uni-row>
				<view class="divider" />
				<button class="mini" type="primary" @click="submit">提交</button>
				<view>
							<!-- 提示信息弹窗 -->
							<uni-popup ref="message" type="message">
								<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
							</uni-popup>
						</view>
			</uni-forms>
		</view>
	</view>
</uni-section>
</template>


<script>
	import {
		addAppointment,sendMessage,listAppointment
	} from "@/api/module/lyq/appoint.js"
	import {
		listEquipment,
		getEquipment
	} from "@/api/module/lyq/equip.js"
	import {
	  getConfigKey
	 } from "@/api/system/config.js"
	export default {
		data() {
			return {
				msgType: 'error',
				messageText: '这是一条成功提示',
				// 遮罩层
				loading: true,
				// 总条数
				total: 0,
				// 基本信息表格数据
				baseinfoList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				datetimerange: [],
				tableriqi: {},
				range: {
					StartTime: this.getStartTime(),
					EndTime: this.getEndTime()
				},
				a:{},
				table: {},
				riqi: {
					pageNum: 1,
					pageSize: 10,
					studentId: null,
					department: null,
					name: null,
					gender: null,
					phone: null,
					idCard: null,
					teacherName: null,
					teacherId: null,
					equipmentType: null,
					applicationDepartment: null,
					instrumentId: null,
					instrumentName: null,
					modelNumber: null,
					specification: null,
					unitPrice: null,
					classifyNumber: null,
					purchaseDate: null,
					receiverId: null,
					receiverName: null,
					manufacturers: null,
					storageDate: null,
					storageLocation: null,
					expenditureSubject: null,
					useDirection: null,
					firstUse: null,
					appointmentStart: null,
					appointmentEnd: null,
					sbumitTime: null,
					auditStatus: null,
					teacherResult: null,
					adminResult: null,
					teacherTime: null,
					adminTime: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				form: {
					studentId: null,
					department: null,
					name: null,
					gender: null,
					phone: null,
					idCard: null,
					teacherName: null,
					teacherId: null,
					equipmentType: null,
					applicationDepartment: null,
					instrumentId: null,
					instrumentName: null,
					modelNumber: null,
					specification: null,
					unitPrice: null,
					classifyNumber: null,
					purchaseDate: null,
					receiverId: null,
					receiverName: null,
					manufacturers: null,
					storageDate: null,
					storageLocation: null,
					expenditureSubject: 0,
					useDirection: 0,
					firstUse: 1,
					appointmentStart: null,
					appointmentEnd: null,
					sbumitTime: this.getNowTime(),
					auditStatus: 0,
					teacherResult: null,
					adminResult: 0,
					assistResult: 0,
					teacherTime: null,
					adminTime: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: 0,
					note2: null,
					note3: 0,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null

				},
				equipType: {},
				equipOptions: [],
				name1: [{
						value: 0,
						text: "科研"
					},
					{
						value: 1,
						text: "教学"
					},
				],
				name2: [{
						value: 0,
						text: "是"
					},
					{
						value: 1,
						text: "否"
					},
				],

			}
		},
		onLoad() {

			this.getNowTime();
		},


		created() {
			this.getConfig();
			const id = this.$route.query.id;
			this.form.appointmentStart = this.$route.query.time;
			this.form.appointmentEnd = this.$route.query.time;
			this.form.note2 = this.$route.query.time;
			this.riqi.note2 = this.$route.query.time;
			this.getDicts("yh_equip_type").then(response => {
				this.equipOptions = response.data;
				for (var i = 0; i < this.equipOptions.length; i++) {
					this.equipType[this.equipOptions[i].dictValue] = this.equipOptions[i].dictLabel
				}
				this.getList()
			});
			// this.range.StartTime=this.$route.query.time;
			// this.range.EndTime=this.$route.query.time;
			if (id) {
				// 获取表详细信息
				getEquipment(id).then(res => {
					this.form.instrumentId = res.data.instrumentId;
					this.form.instrumentName = res.data.instrumentName;
					this.form.equipmentType = res.data.equipmentType;
					this.form.modelNumber = res.data.modelNumber;
					this.form.receiverId = res.data.receiverId;
					this.form.receiverName = res.data.receiverName;
					this.form.applicationDepartment = res.data.applicationDepartment;
					this.form.specification = res.data.specification;
					this.form.unitPrice = res.data.unitPrice;
					this.form.classifyNumber = res.data.classifyNumber;
					this.form.purchaseDate = res.data.purchaseDate;
					this.form.manufacturers = res.data.manufacturers;
					this.form.storageDate = res.data.storageDate;
					this.form.storageLocation = res.data.storageLocation;
					this.riqi.instrumentId = res.data.instrumentId;

				});
			}
		},
		methods: {
			type: function(equipType) {
			
				return this.equipType[equipType]
			},
			change(e) {
				// console.log("e:", e);
			},
			input(e) {
				console.log('输入内容：', e);
				// console.log('日期', this.riqi.note2)
				// console.log('设备id', this.riqi.instrumentId)
				// console.log('时间', new Date())
			},
			getListriqi() {
				console.log("list1：" + this.riqi.instrumentId)
				console.log("list2：" + this.riqi.note2)
				this.loading = true;
				listAppointment(this.riqi).then(res => {
					this.tableriqi = res.rows;
					this.total = res.total;
					this.loading = false;
				});
			},
			getList() {
				this.loading = true;
				listAppointment(this.queryParams).then(res => {
					this.a = res.rows;
					this.total = res.total;
					this.loading = false;
				});
			},
			getNowTime() {

				var now = new Date();
				var year = now.getFullYear(); //得到年份
				var month = now.getMonth(); //得到月份
				var date = now.getDate(); //得到日期
				month = month + 1;
				month = month.toString().padStart(2, "0");
				date = date.toString().padStart(2, "0");

				var defaultDate = `${year}-${month}-${date} 8:00:00`;
				return defaultDate;
			},
			getStartTime() {
				const time = this.$route.query.time;
				// var now = new Date();
				// var year = now.getFullYear(); //得到年份
				// var month = now.getMonth(); //得到月份
				// var date = now.getDate(); //得到日期
				// month = month + 1;
				// month = month.toString().padStart(2, "0");
				// date = date.toString().padStart(2, "0");
				// var defaultDate = `${year}-${month}-${date} 8:00:00`;
				var defaultDate = `${time} 00:00:00`;
				return defaultDate;
			},
			getEndTime() {
				const time = this.$route.query.time;
				var defaultDate = `${time} 23:30:00`;
				return defaultDate;;
			},
			getBeforeDate(num, time) {
				let n = num;
				let d = '';
				if (time) {
					d = new Date(time);
				} else {
					d = new Date();
				}
				let year = d.getFullYear();
				let mon = d.getMonth() + 1;
				let day = d.getDate();
				if (day <= n) {
					if (mon > 1) {
						mon = mon - 1;
					} else {
						year = year - 1;
						mon = 12;
					}
				}
				d.setDate(d.getDate() - n);
				year = d.getFullYear();
				mon = d.getMonth() + 1;
				day = d.getDate();
				let s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
				return s;
			},
			getConfig(){
			    getConfigKey("sys.assist.receiver").then(response => {
			          this.assistment = response.msg;
			        });
			   },
			submit(ref) {
				this.$refs.form.validate().then(res => {
					if( this.form.expenditureSubject == null || this.form.useDirection == null || this.form.firstUse == null) 
					{
					  // this.$modal.msgSuccess("信息不全");
					  this.$modal.msgError("信息不全");
					  return;}
					addAppointment(this.form).then(response => {
						sendMessage(this.form.receiverId,this.form.receiverName,this.form.instrumentName,this.form.storageLocation,this.form.appointmentStart,this.form.appointmentEnd,this.assistment,this.form.specification,this.form.instrumentId)
						this.$modal.msgSuccess("提交成功")
						setTimeout(function() {
							uni.navigateTo({
								url: `/pages/module/shao/xiangxi`
							})
						}, 200);
					})
					.catch((err)=>{
						this.$modal.msgError("该时间已被预约/信息不全");
					});

				})
			}
		},
	}
</script>

<style lang="scss">
	.uni {
		width: 190px;
		height: 20px;
		float: right;
		margin-right: 3%;
		position: relative;
		text-align: right;
	}

	.uni2 {
		height: 20px;
		width: 50px;
		text-align: right;
		
	}

	.uni1 {
		width: 200px;
		height: 25px;
		
		float: right;
		position: relative;
		text-align: right;
	}

	.re-button1 {
		display: flex;
	}

	.re-button2 {
		margin-left: 75%;
	}

	.first {
		margin-top: 3%;
	}

	page {
		background-color: #ffffff;
	}



	.mini {
		width: 90%;
  margin-top: 15px;
    display: flex;
    justify-content: space-around;
	}

	.title {
		/* display: block; */
		font-weight: bold;
		margin-left: 3%;
		text-align: left;
	}
	.title1 {
		/* display: block; */
		font-weight: bold;
		margin-left: 3%;
		margin-top: 3%;
		text-align: left;
	}

	.content {
		/* display: block; */
		text-align: right;
		/* margin-left: 60%; */
		/* margin-right: 5%; */
		/* margin-top: -5%; */
	}
	.content1 {
		/* display: block; */
		text-align: right;
		margin-top: 3%;
		/* margin-left: 60%; */
		/* margin-right: 5%; */
		/* margin-top: -5%; */
	}

	.divider {
		margin-top: 3%;
		margin-bottom: 3%;
		margin-right: 2%;
		margin-left: 2%;
		background: #E0E3DA;
		width: 100%;
		height: 1rpx;
	}

	.divider.last {
		margin-bottom: 8%;
	}

	.body {
		background-color: #fff;
		padding-left: 10px;
		padding-right: 10px;
	}

	.ui {
		padding-top: 20px;
	}

	.divider {
		margin-top: 3%;
		margin-bottom: 3%;
		margin-right: 2%;
		margin-left: 2%;
		background: #E0E3DA;
		width: 100%;
		height: 1rpx;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}
	
</style>
